<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index</title>
<link rel="stylesheet" type="text/css" href="resources/css/style.css">
<script type="text/javascript" src="resources/js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="resources/js/utility.js"></script>
<script type="text/javascript">
			function check() {
				if($("#username").val() == "" || $("#username").val() == "undefined") {
					$("#username").focus();
					$("#usernameError").html("Username Vuoto");
					return false;
				}
				if($("#password").val() == "" || $("#password").val() == "undefined") {
					$("#password").focus();
					$("#passwordError").html("Password vuota");
					return false;
				}
				$.ajax({
					url :  "login.htm",
					type : "POST",
					data : ({
						username : $('#username').val(),
						password : $("#password").val()
					}),
					success : function(res) {
						if (res == "welcomeUser") {
							$("#login").action = "welcomeUser.htm";
							$("#login").submit();
						} else if(res == "welcomeAdmin") {
							$("#login").action = "welcomeAdmin.htm";
							$("#login").submit();
						} else {
							$('#error').html('<h2>Errore nel login</h2>');
						}
					}
				});
			}
			
		</script>
</head>
<body>
	<div class="box">
		Se non sei registrato <a href="#" onclick="redir('addForm.htm')">clicca qui</a>
		<h3>Accedi per utilizzare i nostri servizi:</h3>
		<form id="login" method="post">
			<table>
				<tr>
					<td>Username:</td>
					<td><input type="text" id="username" name="username" /></td>
					<td id="usernameError"></td>
				</tr>
				<tr>
					<td>Password:</td>
					<td><input type="password" id="password" name="password" /></td>
					<td id="passwordError"></td>
				</tr>
				<tr>
					<td><input class="button" type="button" value="Login" onclick="check()"/></td>
					<td><input class="button" type="reset" value="Annulla"></td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>